import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:xindong/common/xindong_sezhi.dart';

class XinDongTextField extends StatelessWidget {
  // 自动对焦
  final bool autofocus;

  // 使能
  final bool enable;

  // 是否隐藏稳步·代替
  final bool obscureText;

  // 占位符
  final String hintText;

  // 焦点
  final FocusNode? focusNode;

  // 输入格式化
  final List<TextInputFormatter>? inputFormatters;

  // 对齐方式
  final TextAlign textAlign;

  // 键盘样式
  final TextInputType? keyboardType;

  // 前缀图标
  final Widget? prefixIcon;

  // 后缀图标
  final Widget? suffixIcon;

  // 编辑控制器
  final TextEditingController? controller;

  final TextStyle? style;
  final TextStyle? hintStyle;
  final TextInputAction? textInputAction;
  final EdgeInsetsGeometry? contentPadding;

  // 编辑回调
  final ValueChanged<String>? onChanged;
  final ValueChanged<String>? onSubmitted;

  // 构造函数
  const XinDongTextField({
    Key? key,
    this.enable = true,
    this.autofocus = false,
    this.hintText = '',
    this.controller,
    this.contentPadding,
    this.inputFormatters,
    this.keyboardType,
    this.textAlign = TextAlign.left,
    this.textInputAction,
    this.obscureText = false,
    this.focusNode,
    this.prefixIcon,
    this.suffixIcon,
    this.style,
    this.hintStyle,
    this.onChanged,
    this.onSubmitted,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return TextField(
      maxLines: 1,
      enabled: enable,
      autofocus: autofocus,
      controller: controller,
      obscureText: obscureText,
      focusNode: focusNode,
      textAlign: textAlign,
      textInputAction: textInputAction,
      style: style ?? const TextStyle(color: DZColors.titleColor, fontSize: 16.0, fontWeight: FontWeight.normal, height: 1.2),
      // 只允许输入数字等设置
      inputFormatters: inputFormatters ?? [],
      // 键盘类型
      keyboardType: keyboardType ?? TextInputType.text,
      decoration: InputDecoration(
        // 设置这个之后，居中
        contentPadding: contentPadding ?? const EdgeInsets.all(0),
        // 占位符
        hintText: hintText,
        // 占位符样式
        hintStyle: hintStyle ?? const TextStyle(color: DZColors.placeholderColor, fontSize: 16.0, fontWeight: FontWeight.normal, height: 1.2),
        // 前缀左侧视图
        prefixIcon: prefixIcon,
        // prefixIconConstraints: BoxConstraints(maxWidth: 44),
        // 后缀右侧视图
        suffixIcon: suffixIcon,
        // 边框、圆角
        border: const OutlineInputBorder(borderSide: BorderSide.none),
      ),
      onChanged: onChanged,
      onSubmitted: onSubmitted,
    );
  }
}
